package com.onsproject.nzbgetremote;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class BasicCalls extends Fragment {

	private LoadInfoTask mTask;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		return inflater.inflate(R.layout.basiccalls_fragment, container, false);
	}

	@Override
	public void onResume() {
		super.onResume();
		if (mTask != null) {
			mTask.cancel(true);
			mTask = null;
		}
		mTask = new LoadInfoTask();
		mTask.execute("");
	}

	private class LoadInfoTask extends AsyncTask<String, String, Boolean> {

		private String mVersion;

		@Override
		protected Boolean doInBackground(String... params) {
			Settings settings = Settings.getInstance(getActivity());
			mVersion = (String) settings.callMethod(getActivity(), "version");
			return null;
		}

		@Override
		protected void onPostExecute(Boolean result) {
			((TextView) getActivity().findViewById(R.id.textView1)).setText("NZBGet server version: " + mVersion);
		};
	};
}
